#include "utils.hpp"

void Test1(const std::string &filePath)
{
    Cloud::FileUtils fu(filePath);
    std::cout << fu.getSize() << std::endl;
    std::cout << fu.getATime() << std::endl;
    std::cout << fu.getMTime() << std::endl;
    std::cout << fu.getFileName() << std::endl;
}

void Test2(const std::string &filePath)
{
    Cloud::FileUtils(filePath).compress(filePath + ".lz");
    Cloud::FileUtils(filePath).deCompress(filePath + "2");
}

void Test3(const std::string &filePath)
{
    Cloud::FileUtils f(filePath);
    std::cout << f.exists() << std::endl;
    f.createDirectory();
    std::cout << f.exists() << std::endl;
    std::vector<std::string> Path;
    f.scanDirectory(&Path);
    for (auto &e : Path)
        std::cout << e << std::endl;
}

void TestJson()
{
    // 数据初始化
    double a = 1.11;
    std::string b("Hello World");
    int arr[]{1, 2, 3};

    Json::Value va;
    va["double"] = a;
    va["string"] = b;
    for (int i = 0; i < 3; i++)
        va["arr"].append(arr[i]);

    std::string str;
    Cloud::JsonUtils::serialize(va, &str);

    std::cout << "Serialized JSON: ";
    std::cout << str << std::endl;

    Json::Value v;
    Cloud::JsonUtils::deSerialize(str, &v);

    double a2 = v["double"].asDouble();
    std::string b2 = v["string"].asString();
    int arr2[3];
    for (int i = 0; i < 3; i++)
        arr2[i] = v["arr"][i].asInt();

    std::cout << "\nDeserialized Data:\n";
    std::cout << "a2: " << a2 << std::endl;
    std::cout << "b2: " << b2 << std::endl;
    std::cout << "arr2: ";
    for (int i = 0; i < 3; i++)
        std::cout << arr2[i] << " \n"[i == 2];
    exit(0);
}

void Usage(const std::string &str)
{
    std::cout << "Usage:\n\t";
    std::cout << str << " [number] [filepath]\n";
}

int main(int argc, char *argv[])
{
    if (argc == 1)
        TestJson();
    if (argc == 3)
    {
        if (argv[1][0] == '1')
            Test1(argv[2]);
        if (argv[1][0] == '2')
            Test2(argv[2]);
        if (argv[1][0] == '3')
            Test3(argv[2]);
    }
    else
    {
        Usage(argv[0]);
    }
    return 0;
}